
//1839.所有元音按顺序排布的最长子字符串
class Solution {
public:
    int longestBeautifulSubstring(string word) {
        vector<char> vowel({'a','e','i','o','u'});

        int n=word.size();
        int i=0,ret=0;
        while(i<n)
        {
            while(i<n&&word[i]!='a') i++;  //找以a开头的字符串

            int start=i,pos=0;
            for(pos=0;pos<5;pos++)  //遍历所有元音字符
            {
                if(word[i]!=vowel[pos]) break;  //判断是否存在该元音字符
                while(word[i]==vowel[pos]) i++;
            }        
            if(pos==5) ret=max(ret,i-start);  //更新答案
        }
        return ret;
    }
};